using Shared;
using System;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.Music;
using HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock;
using HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView;
namespace HDL_ON.UI.UI2.FuntionControlView.HisenseTV
{
///
/// 海信电视界面
///
public class HisenseTvPage : BaseFramLayout
{
#region -------变量声明---------
///
/// 设备
///
private Function device;
///
/// 上一级界面的设备名字控件
///
private Button btnDeviceName;
///
/// 上一级界面的房间名字控件
///
private Button btnRoomName;
///
/// 上一级界面的收藏控件
///
private Button btnCollectionIcon;
///
/// 头部布局
///
private TopView topView;
///
///中部布局
///
VerticalScrolViewLayout vv;
///
/// 当前设备名称
///
private Button btnOpenCurrDeviceName;
///
/// 区域
///
private Button btnOpenCurrDeviceRoom;
///
///收藏图标
///
private Button btnOpenCollectIcon;
CustomFrameLayout shouyeFL;
CustomFrameLayout kaijiFL;
CustomFrameLayout guanFL;
Button btn_jia;
Button btn_jian;
CustomButton caidanBtn;
CustomButton bofangBtn;
CustomButton zantingBtn;
CustomButton kuaijinBtn;
CustomButton kauituiBtn;
CustomButton jingyinBtn;
CustomButton shezhiBtn;
CustomButton jiechujingyinBtn;
CustomButton fanhuiBtn;
MenuFramLayout muenFrameLayout;
SourceFrameLayout sourceFrameLayout;
///
/// 表示来自那个界面
///
private CommonMethod.Comerom comerom;
///
/// 删除设备后需要更新界面的回调
///
public Action action;
#endregion
///
/// 构造函数
///
/// 设备
/// 上一级界面的设备名字控件(注:不能传null,没有可以传new Button())
/// 上一级界面的房间名字控件(注:不能传null,没有可以传new Button())
/// 上一级界面的房间名字控件(注:不能传null,没有可以传new Button())
public HisenseTvPage(Function function, Button btnDeviceName, Button btnRoomName, Button btnCollectionIcon, CommonMethod.Comerom comerom, Action action)
{
this.device = function;
this.btnDeviceName = btnDeviceName;
this.btnRoomName = btnRoomName;
this.btnCollectionIcon = btnCollectionIcon;
this.comerom = comerom;
this.action = action;
}
public void Show()
{
//初始化UI
this.InitTopUI();
this.InitOpenUI();
//初始化事件
this.EventListener();
//读取数据
this.ReadData();
}
///
/// 注册事件
///
private void EventListener()
{
//返回
this.topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
{
this.RemoveFromParent();
};
//设置
this.topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
{
CommonMethod.Current.MainThread(() =>
{
//调用秀绕的界面
var infoView = new UI.FunctionBaseInfoSetPage(this.device, () =>
{
if (this.btnDeviceName == null || this.btnRoomName == null || this.device == null)
{
return;
}
////刷新显示
this.btnDeviceName.Text = this.device.name;
this.btnRoomName.Text = this.device.GetRoomListName();
//
this.btnOpenCurrDeviceName.Text = this.device.name;
this.btnOpenCurrDeviceRoom.Text = this.device.GetRoomListName();
this.CalculatedPosition();//重新计算宽度
});
infoView.actionDel += () =>
{
//解绑设备后
this.RemoveFromParent();
this.action?.Invoke();
};
MainPage.BasePageView.AddChidren(infoView);
infoView.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
});
};
//收藏
this.btnOpenCollectIcon.MouseUpEventHandler += (sender, e) =>
{
btnOpenCollectIcon.IsSelected = this.device.collect = !btnOpenCollectIcon.IsSelected;
this.device.CollectFunction();
this.btnCollectionIcon.IsSelected = btnOpenCollectIcon.IsSelected;
};
//首页
shouyeFL.SetClickListener((fl, btnImage, btnText) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.home_page, "");
});
//开机
kaijiFL.SetClickListener((fl, btnImage, btnText) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.wol, "on");
});
//关机
guanFL.SetClickListener((fl, btnImage, btnText) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.on_off, "off");
});
//音量+
btn_jia.MouseUpEventHandler += (sender, e) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.volume_add, "");
this.SetButtonIsSelected(btn_jia);
};
//音量-
btn_jian.MouseUpEventHandler += (sender, e) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.volume_subtract, "");
this.SetButtonIsSelected(btn_jian);
};
//菜单
caidanBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "11");
});
//播放
bofangBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.media_play, "");
});
//暂停
zantingBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.media_pause, "");
});
//快进
kuaijinBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.fast_forward, "");
});
//快退
kauituiBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.fast_back, "");
});
//静音
jingyinBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.mute, "1");
});
//设置
shezhiBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.system_setting, "");
});
//解除静音
jiechujingyinBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.mute, "0");
});
//返回
fanhuiBtn.SetClickListener((btn) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "5");
});
//上
muenFrameLayout.SetTopClickListener((muen) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "0");
});
//下
muenFrameLayout.SetBottomClickListener((muen) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "1");
});
//左
muenFrameLayout.SetLeftClickListener((muen) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "2");
});
//右
muenFrameLayout.SetRightClickListener((muen) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "3");
});
//OK
muenFrameLayout.SetOkClickListener((muen) =>
{
ControlCommand(HisenseTVFunctionalAttributeConstant.operation, "4");
});
//信号源
sourceFrameLayout.selectAction += (key) =>
{
var p = new UI2.Intelligence.Automation.PublicInterface();
var dic = p.GetHisenseSignalSourceDic();
string value = p.GetValue(dic, key);
ControlCommand(HisenseTVFunctionalAttributeConstant.signal, value);
};
}
///
/// 发送控制属性指令
///
/// 功能属性(语雀上定义的)
/// 值
/// 结果回调(默认不回调)
private void ControlCommand(string key, string value, Action action = null)
{
try
{
if (this.device == null)
{
//设备不在线控制失败
Application.RunOnMainThread(() =>
{
CommonMethod.Current.ShowTip(Language.StringByID(StringId.shebeibuzaixian), 3);
});
return;
}
if (!this.device.online && key != HisenseTVFunctionalAttributeConstant.wol)
{
//设备不在线控制失败
Application.RunOnMainThread(() =>
{
CommonMethod.Current.ShowTip(Language.StringByID(StringId.shebeibuzaixian), 3);
});
return;
}
Dictionary dic = new Dictionary();
dic.Add(key, value);
Send.Current.SendControlCommand(this.device, dic, action);
}
catch { }
}
///
/// 初始化数据
///
private void ReadData()
{
if (this.device == null)
{
return;
}
CommonMethod.Current.Loading.Start();
CommonMethod.Current.SunThread(() =>
{
try
{
var isRefreshDeviceStatus = Send.Current.RefreshDeviceStatus(new List { this.device.deviceId });
if (isRefreshDeviceStatus)
{
var fun = Send.Current.GetDeviceInfo(this.device.deviceId);
if (fun != null)
{
//更新真实在线状态
this.device.online = fun.online;
}
}
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
CommonMethod.Current.Loading.Hide();
});
}
});
}
#region -------界面布局---------
///
/// 初始化【开机】界面
///
private void InitOpenUI()
{
#region ---界面布局---
vv = new VerticalScrolViewLayout
{
Y = topView.fLayout.Bottom,
Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
};
this.AddChidren(vv);
var baseOpenFL = new BaseFramLayout();
vv.AddChidren(baseOpenFL);
var backgroundOpenFl = new FrameLayout
{
Y = Application.GetRealHeight(24),
X = Application.GetRealWidth(24),
Height = Application.GetRealHeight(648-60),
Width = Application.GetRealWidth(327),
BackgroundImagePath = "HisenseTv/onbj.png",
};
baseOpenFL.AddChidren(backgroundOpenFl);
baseOpenFL.AdjustRealHeight(16);
btnOpenCollectIcon = new Button
{
X = Application.GetRealWidth(273),
Y = Application.GetRealHeight(14),
Width = Application.GetRealWidth(40),
Height = Application.GetRealWidth(40),
UnSelectedImagePath = "MusicIcon/collect.png",
SelectedImagePath = "MusicIcon/collectSelected.png",
IsSelected = this.device.collect,
};
backgroundOpenFl.AddChidren(btnOpenCollectIcon);
btnOpenCurrDeviceName = new Button
{
TextSize = TextSize.Text24,
TextColor = MusicColor.Text18Color,
Width = Application.GetRealWidth(160),
Height = Application.GetRealHeight(33),
Y = Application.GetRealHeight(16),
X = Application.GetRealWidth(16),
Text = this.device.name,
TextAlignment = TextAlignment.CenterLeft,
IsBold = true
};
backgroundOpenFl.AddChidren(btnOpenCurrDeviceName);
btnOpenCurrDeviceRoom = new Button
{
TextSize = TextSize.Text12,
TextColor = MusicColor.MusicNoTxetColor,
Width = Application.GetRealWidth(160),
Height = Application.GetRealHeight(17),
Y = btnOpenCurrDeviceName.Bottom + Application.GetRealHeight(4),
X = Application.GetRealWidth(16),
Text = this.device.GetRoomListName(),
TextAlignment = TextAlignment.CenterLeft,
};
backgroundOpenFl.AddChidren(btnOpenCurrDeviceRoom);
int yHeight = btnOpenCurrDeviceRoom.Bottom + Application.GetRealHeight(16);
shouyeFL = new CustomFrameLayout();
backgroundOpenFl.AddChidren(shouyeFL);
shouyeFL.X = Application.GetRealWidth(24);
shouyeFL.Y = yHeight;
shouyeFL.AddImageView();
shouyeFL.AddTextButtonView();
shouyeFL.GetImageButton().UnSelectedImagePath = "HisenseTv/shouye.png";
shouyeFL.GetImageButton().SelectedImagePath = "HisenseTv/shouyeSelected.png";
shouyeFL.GetTextButton().TextID = StringId.shouye;
kaijiFL = new CustomFrameLayout();
backgroundOpenFl.AddChidren(kaijiFL);
kaijiFL.X = shouyeFL.Right + Application.GetRealWidth(37);
kaijiFL.Y = yHeight;
kaijiFL.AddImageView();
kaijiFL.AddTextButtonView();
kaijiFL.GetImageButton().UnSelectedImagePath = "HisenseTv/kai.png";
kaijiFL.GetImageButton().SelectedImagePath = "HisenseTv/kaiguanSelected.png";
kaijiFL.GetTextButton().TextID = StringId.kaiji;
guanFL = new CustomFrameLayout();
backgroundOpenFl.AddChidren(guanFL);
guanFL.X = kaijiFL.Right + Application.GetRealWidth(37);
guanFL.Y = yHeight;
guanFL.AddImageView();
guanFL.AddTextButtonView();
guanFL.GetImageButton().UnSelectedImagePath = "HisenseTv/guan.png";
guanFL.GetImageButton().SelectedImagePath = "HisenseTv/kaiguanSelected.png";
//guanFL.GetImageButton().UnSelectedImagePath = "HisenseTv/caidan.png";
guanFL.GetTextButton().TextID = StringId.guanji;
var yinliangFL = new FrameLayout();
backgroundOpenFl.AddChidren(yinliangFL);
yinliangFL.Height = Application.GetRealHeight(146-16);
yinliangFL.Width = Application.GetRealWidth(68);
yinliangFL.Y = Application.GetRealHeight(260-8-20);
yinliangFL.X = shouyeFL.X;
yinliangFL.BackgroundColor = 0xFFF2F3F7;
yinliangFL.Radius = (uint)Application.GetRealWidth(34);
btn_jia = new Button
{
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
UnSelectedImagePath = "HisenseTv/yingliangjia.png",
SelectedImagePath = "HisenseTv/yingliangjiaSelected.png",
Y = Application.GetRealHeight(16),
Gravity = Gravity.CenterHorizontal,
};
yinliangFL.AddChidren(btn_jia);
Button btnText = new Button
{
Y = Application.GetRealHeight(63-8),
Height = Application.GetRealHeight(20),
//Text = "音量",
TextID = StringId.yinliang,
TextColor = MusicColor.TextColor,
TextSize = TextSize.Text14,
Gravity = Gravity.CenterHorizontal,
};
yinliangFL.AddChidren(btnText);
btn_jian = new Button
{
Y = Application.GetRealHeight(98-8),
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
UnSelectedImagePath = "HisenseTv/yingliangjian.png",
SelectedImagePath = "HisenseTv/yingliangjianSelected.png",
Gravity = Gravity.CenterHorizontal,
};
yinliangFL.AddChidren(btn_jian);
int bottomValue= 4;
caidanBtn = new CustomButton();
caidanBtn.TextID = StringId.caidan;
caidanBtn.Y = shouyeFL.Bottom + Application.GetRealHeight(bottomValue);
caidanBtn.X = shouyeFL.X;
backgroundOpenFl.AddChidren(caidanBtn);
bofangBtn = new CustomButton();
bofangBtn.TextID = StringId.bofang;
bofangBtn.Y = shouyeFL.Bottom + Application.GetRealHeight(bottomValue);
bofangBtn.X = yinliangFL.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(bofangBtn);
zantingBtn = new CustomButton();
zantingBtn.TextID = StringId.zanting;
zantingBtn.Y = shouyeFL.Bottom + Application.GetRealHeight(bottomValue);
zantingBtn.X = bofangBtn.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(zantingBtn);
int bottomValue1 = 8;
kuaijinBtn = new CustomButton();
kuaijinBtn.TextID = StringId.kuaijin;
kuaijinBtn.Y = bofangBtn.Bottom + Application.GetRealHeight(bottomValue1);
kuaijinBtn.X = yinliangFL.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(kuaijinBtn);
kauituiBtn = new CustomButton();
kauituiBtn.TextID = StringId.kuaitui;
kauituiBtn.Y = bofangBtn.Bottom + Application.GetRealHeight(bottomValue1);
kauituiBtn.X = kuaijinBtn.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(kauituiBtn);
jingyinBtn = new CustomButton();
jingyinBtn.TextID = StringId.jingyin;
jingyinBtn.Y = kuaijinBtn.Bottom + Application.GetRealHeight(bottomValue1);
jingyinBtn.X = yinliangFL.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(jingyinBtn);
shezhiBtn = new CustomButton();
shezhiBtn.TextID = StringId.shezhi;
shezhiBtn.Y = kuaijinBtn.Bottom + Application.GetRealHeight(bottomValue1);
shezhiBtn.X = jingyinBtn.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(shezhiBtn);
jiechujingyinBtn = new CustomButton();
jiechujingyinBtn.TextID = StringId.jiechujingyin;
jiechujingyinBtn.Y = jingyinBtn.Bottom + Application.GetRealHeight(bottomValue1);
jiechujingyinBtn.X = yinliangFL.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(jiechujingyinBtn);
fanhuiBtn = new CustomButton();
fanhuiBtn.TextID = StringId.fanhui;
fanhuiBtn.Y = jingyinBtn.Bottom + Application.GetRealHeight(bottomValue1);
fanhuiBtn.X = jiechujingyinBtn.Right + Application.GetRealWidth(37);
backgroundOpenFl.AddChidren(fanhuiBtn);
TypeFrameLayout typeFrameLayout = new TypeFrameLayout();
typeFrameLayout.middLayout.Y = yinliangFL.Bottom + Application.GetRealHeight(16);
typeFrameLayout.AddView(backgroundOpenFl);
muenFrameLayout = new MenuFramLayout();
muenFrameLayout.Y = Application.GetRealHeight(482-60);
muenFrameLayout.AddView(backgroundOpenFl);
sourceFrameLayout = new SourceFrameLayout();
sourceFrameLayout.Y = Application.GetRealHeight(482-60);
backgroundOpenFl.AddChidren(sourceFrameLayout);
sourceFrameLayout.LoadSourcePage();
muenFrameLayout.Visible = true;
sourceFrameLayout.Visible = false;
typeFrameLayout.SetLfteClickListener(() =>
{
muenFrameLayout.Visible = true;
sourceFrameLayout.Visible = false;
});
typeFrameLayout.SetRightClickListener(() =>
{
muenFrameLayout.Visible = false;
sourceFrameLayout.Visible = true;
});
#endregion
}
///
/// 初始化头部
///
private void InitTopUI()
{
this.BackgroundColor = MusicColor.ViewColor;
this.topView = new TopView();
this.topView.setBtn.Visible = true;
this.topView.topNameBtn.TextID = StringId.dianshi;
this.AddChidren(topView.TopFLayoutView());
}
///
/// 重新计算宽度(设备名称,房间控件)
///
private void CalculatedPosition()
{
//开机状态
this.btnOpenCurrDeviceName.Width = this.btnOpenCurrDeviceName.GetTextWidth();
this.btnOpenCurrDeviceName.Width += 10;
if (this.btnOpenCurrDeviceName.GetTextWidth() > this.btnOpenCollectIcon.X)
{
//重新计算宽度
this.btnOpenCurrDeviceName.Width = this.btnOpenCollectIcon.X + Application.GetRealWidth(-10);
}
this.btnOpenCurrDeviceRoom.Width = this.btnOpenCurrDeviceRoom.GetTextWidth();
this.btnOpenCurrDeviceRoom.Width += 10;
if (this.btnOpenCurrDeviceRoom.GetTextWidth() > this.btnOpenCollectIcon.X)
{
//重新计算宽度
this.btnOpenCurrDeviceRoom.Width = this.btnOpenCollectIcon.X + Application.GetRealWidth(-20 - 10);
}
//this.cellFrame.X = this.btnCurrDeviceRoom.Right + Application.GetRealWidth(20);
}
#endregion
}
#region -------自定义当前界面的容器---------
///
/// 自定义(首页,关机,菜单)容器
///
class CustomFrameLayout : BaseFramLayout
{
public const int widthFrameLayout = 68;
public const int heightFrameLayout = 68 + 8 + 20;
public const int interval = 37;//行中的列间隔值
public CustomFrameLayout(int width = widthFrameLayout, int height = heightFrameLayout)
{
this.Width = Application.GetRealWidth(width);
this.Height = Application.GetRealHeight(height);
}
Button btnImage = new Button
{
Width = Application.GetRealWidth(68),
Height = Application.GetRealWidth(68),
Gravity = Gravity.TopCenter,
Name = "btnImage",
};
Button btnText = new Button
{
Width = Application.GetRealWidth(68),
Height = Application.GetRealWidth(20),
TextID = StringId.dangqianmenweiguan,
TextSize = TextSize.Text14,
TextColor = MusicColor.TextColor,
SelectedTextColor = MusicColor.MusicTxet14SelectedColor,
TextAlignment = TextAlignment.Center,
Gravity = Gravity.CenterHorizontal,
Name = "btnText",
IsMoreLines = true,
};
public void AddImageView()
{
this.AddChidren(btnImage);
}
public void AddTextButtonView()
{
btnText.Y = Application.GetRealHeight(8) + btnImage.Bottom;
this.AddChidren(btnText);
}
public Button GetImageButton()
{
return this.btnImage;
}
public Button GetTextButton()
{
return this.btnText;
}
///
/// 事件监听方法
///
/// 回调(第一个是父类对象;第二个是图标对象;第三个是状态对象
/// 注意:在SetClickListener()前面调用AddImageView()才有效
/// 注意:在SetClickListener()前面调用AddImageView()才有效
public void SetClickListener(Action action)
{
EventHandler UpClick = (sender, e) =>
{
action?.Invoke(this, btnImage, btnText);
SetButtonIsSelected(btnImage);
};
this.MouseUpEventHandler += UpClick;
btnImage.MouseUpEventHandler += UpClick;
btnText.MouseUpEventHandler += UpClick;
}
}
///
/// 按键容器
///
class CustomButton : Button
{
public CustomButton()
{
this.Width = Application.GetRealWidth(68);
this.Height = Application.GetRealHeight(38);
this.TextSize = 14;
this.TextColor = MusicColor.TextColor;
this.SelectedTextColor = MusicColor.MusicTxet14SelectedColor;
this.TextAlignment = TextAlignment.Center;
this.IsMoreLines = true;
this.BackgroundColor = 0xFFF2F3F7;
this.SelectedBackgroundColor = 0xffECEDEE;
this.Radius = (uint)Application.GetRealHeight(19);
this.Padding = new Padding(0, 0, 0, 0);
}
///
/// 事件监听方法
///
/// 回调(第一个是父类对象
public void SetClickListener(Action